package com.mt.api.modules.controller;

import com.mt.log.annotation.Log;
import com.mt.api.modules.domain.bo.AppCargoBo;
import com.mt.api.modules.domain.bo.AppCargoEditBo;
import com.mt.api.modules.domain.bo.CargoPageBo;
import com.mt.api.modules.domain.bo.CargoReportBo;
import com.mt.api.modules.domain.vo.CargoSalesReportVo;
import com.mt.api.modules.domain.vo.CargoSimpleVo;
import com.mt.api.modules.service.AppCargoService;
import com.mt.api.util.ParamsValid;
import com.mt.common.response.WebResponse;
import com.mt.common.response.WebResponseUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * @author plover
 * @date 2020-07-06
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "cargo管理")
@RequestMapping("/app/cargo")
public class AppCargoController {

    private final AppCargoService cargoService;

    @PostMapping("/edit")
    @Log("款号保存")
    @ApiOperation(value = "", notes = "款号保存", httpMethod = "POST")
    public WebResponse editCargo(@RequestBody AppCargoEditBo bo) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("请输入商品款号", bo.getCargoNo());
        valid.validNotNull("请输入商名称", bo.getCargoName());
        // valid.validNotNull("请上传商品图片", bo.getPicUrl());
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return cargoService.editCargo(bo);
    }

    @PostMapping("/on")
    @Log("款号上架")
    @ApiOperation(value = "", notes = "款号上架", httpMethod = "POST")
    public WebResponse cargoOn(@RequestBody AppCargoBo appCargoBo) {
        return cargoService.cargoOn(appCargoBo);
    }

    @PostMapping("/off")
    @Log("款号上架")
    @ApiOperation(value = "", notes = "款号下架", httpMethod = "POST")
    public WebResponse cargoOff(@RequestBody AppCargoBo appCargoBo) {
        return cargoService.cargoOff(appCargoBo);
    }

    @GetMapping("/getByCargoNo")
    public WebResponse<CargoSimpleVo> getByCargoNo(String cargoNo) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("请输入款号", cargoNo);
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return cargoService.getByCargoNo(cargoNo);
    }

    @GetMapping("/getByCargoId")
    @Log("查询商品")
    public WebResponse<CargoSimpleVo> getByCargoId(Integer cargoId) {
        ParamsValid valid = new ParamsValid();
        valid.validNotNull("请输入cargoId", cargoId);
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return cargoService.getByCargoId(cargoId);
    }

    @GetMapping("/getCargoPage")
    public WebResponse getCargoPage(CargoPageBo bo) {
        ParamsValid valid = new ParamsValid();
        if (!valid.isValid()) {
            return WebResponseUtils.errorParam(valid.getMsg());
        }
        return cargoService.getCargoPage(bo);
    }

    @GetMapping("/sales/report")
    @Log("商品每日销量统计")
    public WebResponse<CargoSalesReportVo> salesReport(CargoReportBo bo) {
        return cargoService.salesReport(bo);
    }

}